<style>
	.gary_a1{color: #AAA1A1;}
	.bl_34{color: #343434;}
	.blue_76{color: #768196;}
	.middle{border-bottom: 1rpx solid rgba(0, 0, 0, 0.08);}
</style>

<template>
	<view class="mainPage" :style="{'padding-top': `${$store.state.safeArea.top || 0}px`, 'padding-bottom': `${$store.state.safeArea.bottom || 0}px`}">
		<public-head :title="title"></public-head>
		<view class="w100pc h2"></view>
		<view class="" style="background: #fff;">
			<view class="lrmg-30">
				<view class="fsb" :class="[i == list.length - 1 ? '' : 'middle']" style="height: 80rpx;width: 100%;" v-for="(it,i) in list" :key="i">
					<view class="bl_34 mg-l-10">{{it.name}}</view>
					<view class="flex aic">
						<view class="blue_76 mg-r-40 flex aic" @click="too(2,it.id)">
							<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/mykehu/xg.png" style="width:28rpx;height:28rpx" class=""></image>
							<view class="f24 mg-l-10">修改</view>
						</view>
						<view class="blue_76 mg-r-20 mg-l-40 flex aic" @click="shanchu(it.id)"> 
							<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/mykehu/del.png" style="width:28rpx;height:28rpx" class=""></image>
							<view class="f24 mg-l-10">删除</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="" style="width: 100%;height: 200rpx;"></view>
		<view class="flex jc-center" style="position: absolute;left: 0;bottom: 50rpx;width: 100%;">
			<view class="bra10 fff fcc" style="width: 80%;height: 100rpx;background: linear-gradient(219deg, #FF9331 0%, #FE7600 100%);" @click="too(1)">
				<view class="flex aic">
					<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/mykehu/jia.png" style="width:30rpx;height:30rpx" class=""></image>
					<view class="mg-l-10">新建分组</view>
				</view>
			</view>
		</view>
		<u-popup v-model="show" mode="center" length="90%" border-radius="15" :mask-close-able="false">
			<view style="background: #fff;">
				<view class="fcc" style="width: 100%;height: 100rpx;border-bottom: 1px solid #EEEEEE;">
					<view class="weight">删除确认</view>
				</view>
				<view class="tmmgin-40" style="text-align: center;color: #999999;">
					分组删除后将无法恢复，确认删除吗？
				</view>
				<view class="flex aic" style="height: 101rpx;border-top: 1px solid #EEEEEE;">
					<view class="fcc" style="width: calc(50% - 0.5rpx);height: 100rpx;" @click="show = false">
						<view class="">取消</view>
					</view>
					<view class="" style="width: 1rpx;height: 100rpx;background: #eee;"></view>
					<view class="fcc" style="width: calc(50% - 0.5rpx);height: 100rpx;" @click="del">
						<view class="" style="color: #FA6400;">确定</view>
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="shows" mode="center" length="90%" border-radius="15" :mask-close-able="false">
			<view style="background: #fff;">
				<view class="fcc" style="width: 100%;height: 100rpx;border-bottom: 1px solid #EEEEEE;">
					<view class="weight">{{tt == 1 ? '新建' : '编辑'}}分组名称</view>
				</view>
				<view class="tmmgin-40 fcc" style="">
					<input type="text" v-model="fz_name" placeholder="最多输入8个字，支持中英文，数字" maxlength="8" style="width: 88%;height: 100rpx;border: 1px solid #F7F4F4;padding-left: 2%;" class="bra10" />
				</view>
				<view class="flex aic" style="height: 101rpx;border-top: 1px solid #EEEEEE;">
					<view class="fcc" style="width: calc(50% - 0.5rpx);height: 100rpx;" @click="shows = false">
						<view class="">取消</view>
					</view>
					<view class="" style="width: 1rpx;height: 100rpx;background: #eee;"></view>
					<view class="fcc" style="width: calc(50% - 0.5rpx);height: 100rpx;" @click="qued()">
						<view class="" style="color: #FA6400;">确定</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	var that
	import publicHead from "@/components/publicHead/publicHead.vue"
	export default {
		components: {
			publicHead
		},
		data(){
			return{
				title: '管理分组',
				list:[],
				show: false,//删除
				shows: false,//新建或编辑
				tt:0,
				id:'',
				fz_name:''
			}
		},
		onLoad() {
			that = this
			that.get()
		},
		methods:{
			shanchu(id){
				that.id = id
				that.show = true
			},
			del(){
				uni.showLoading({
					mask: true,
					title: '加载中...'
				});
				let postData = {
					group_id:that.id
				}
				that.$postAjax1('DoctorGroup_del_group',postData,function(data){
					uni.hideLoading()
					that.get()
					that.$store.state.fz_type = 0
					that.show = false
				})
			},
			qued(){
				if(that.fz_name == ''){
				uni.showToast({
					title: '请输入名称',
					icon: 'none',
					duration: 1500
				});
				return
				}
				uni.showLoading({
					mask: true,
					title: '加载中...'
				});
				let ser = ''
				let postData = ''
				
				if(that.tt == 1){
					ser = 'DoctorGroup_create_group'
					postData = {
						name:that.fz_name
					}
				}else{
					ser = 'DoctorGroup_edit_group'
					postData = {
						group_id:that.id,
						name:that.fz_name
					}
				}
				that.$postAjax1(ser,postData,function(data){
					uni.hideLoading()
					that.get()
					that.fz_name = ''
					that.$store.state.fz_type = 0
					that.shows = false
				})
			},
			get() {
				that.$postAjax1('DoctorGroup_group_list_num','',function(data){
					let list = data.data.data
					that.list = list
				})
			},
			too(e,id){
				if(e == 2){
					that.id = id
				}
				that.tt = e
				that.shows = true
			}
		}
	}
</script>
